<script type="text/javascript">
	var name = 'nowRunning';
	//var container = '{container}';
	//var nowRn = $('div#'+container);
	var update = function()
	{
		var cont = $('.tester');
		$.get('{base_url}module/gdata/'+name,
			function(res){
				if(0 == res.webinar) cont.html(tpl['message']);
				else cont.html(tpl['webinar']);
				if(debug)
				{
					json = res;
					console.log('responce: ');
					console.log(json);
				}
				cont.autoRender(res).find('a.join').click(join);
				cont.find('a.end').click(end);

			},'json'
		     );
	}
	
	var join = function()
	{
		$.post(this.href, {ctrl : 1}, function(res){
			if(!res.error)
			{
				document.location = res.url;
			}
			else
			{
				$('div#msgBox').html(res.error);
				$('div#msgBox').dialog({ autoOpen: true, title: 'Ошибка!' });
			}
		}, 'json')
		return false;
	}

	var end = function()
	{
		$.post(this.href, {}, function(res){
			if(!res.error)
			{
				//document.location = res.url;
				$.gEmit('updRn');
			}
			else
			{
				$('div#msgBox').html(res.error);
				$('div#msgBox').dialog({ autoOpen: true, title: 'Ошибка!' });
			}
		}, 'json')
		return false;
	}
	
	$(document).ready(function(){
		$.gListern(name, 'updRn', update);
		setInterval(update, 30000);
		
		tpl = {message : '', webinar : ''};
		tpl['message'] = "<tr class='message'><td><div class='text'></div></td></tr>" ;
		$.get('{base_url}module/tpl/runned', function(res){ tpl['webinar'] = res; update('');}); //ev.trigger('updRn');});
		
	});
</script>
<p class='content'>
<h3 class='orange' style='font-size: 18px;'>Текущие вебинары</h3>
<table class='tester'>
        
</table>
</p>
